//
//  JQHomeBannerCollectionCell.m
//  JQLive
//
//  Created by Bruce on 2020/6/12.
//  Copyright © 2020 JQLive. All rights reserved.
//

#import "JQHomeBannerCollectionCell.h"
#import "UIView+Extension.h"

@interface JQHomeBannerCollectionCell ()
/// 封面视图
@property(nonatomic, strong) UIImageView *coverImageView;

@property(nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *defalutImageV;

@end
@implementation JQHomeBannerCollectionCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initData];
        [self initView];
    }
    return self;
}

#pragma mark - Intial Methods

/**
 初始化数据
 */
- (void)initData
{
    
}

/**
 初始化试图
 */
- (void)initView
{
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 6;
    
    [self addCoverImageView];
    [self addTitleLabel];
}

- (void)addCoverImageView
{
    UIImageView *imageView = [[UIImageView alloc] init];
    
    [self.contentView addSubview:imageView];
    [self.contentView sendSubviewToBack:imageView];
    self.coverImageView = imageView;
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.contentView);
        make.height.mas_equalTo(144);
        make.top.left.equalTo(self.contentView);
    }];
    [imageView layoutIfNeeded];
    [imageView round:10 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
    
    self.coverImageView.backgroundColor = [UIColor clearColor];
//    self.coverImageView.backgroundColor = kColorWithHex(0xD0D6EF);//[UIColor grayColor];
    
    self.defalutImageV = [[UIImageView alloc] init];
    [imageView addSubview:self.defalutImageV];
    MY_WEAK;
    [self.defalutImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.center.equalTo(strongSelf.coverImageView);
        make.size.mas_equalTo(CGSizeMake(63,62));
    }];
    self.defalutImageV.image = [UIImage imageNamed:@"home_liveIcon_nor"];
}


- (void)addTitleLabel
{
    UILabel *label = [[UILabel alloc] init];
    label.font = MY_Text_Font_T3;
    label.textColor = UIColorWhite;
    label.numberOfLines = 1;
    [self.contentView addSubview:label];
    self.titleLabel = label;
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.width.mas_equalTo(SCREEN_WIDTH-20-24-80-12);
        make.bottom.mas_equalTo(-12);
    }];
}
#pragma mark - Public Methods

#pragma mark - Private Methods

#pragma mark - Getters and Setters
- (void)setCoverImageView:(NSString *)imageUrl titleStr:(NSString *)titleStr{
//    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:DefaultLoadErrorImage];
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
    
    if (imageData) {
        [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"home_liveIcon_nor"]];
        self.defalutImageV.hidden = YES;
        self.coverImageView.backgroundColor = [UIColor clearColor];
    }else{
        self.defalutImageV.hidden = NO;
        self.coverImageView.backgroundColor = kColorWithHex(0xD0D6EF);
    }
    self.titleLabel.text = titleStr;
}


@end
